<?php

include_once BONE_ROOT.DS.'controllers'.DS.'vars.php';

class controller_project extends controller_theme
{

	public function __construct()
	{
		$my = bone::get_user();

		$task = get('task');

		switch($task)
		{
			case 'guest_list':
			case 'guest_detail':
				break;
			default:
				if($my->guest) $this->redirect( url('./?controller=user&task=login'), '请先登陆', 'error' );
		}
		parent::__construct();
	}
	

	// 项目列表
	public function guest_list()
	{
		$model = bone::get_model('project');
		$projects = $model->get_guest_projects();

		foreach($projects as $project)
		{
			$project->ticket_count = $model->get_ticket_count($project->id);
			$project->completed_ticket_count = $model->get_completed_ticket_count($project->id);
			$project->progress = $model->get_progress($project);
		}

		$template = bone::get_template('project.guest_list');
		$template->set_title('项目列表');
		$template->set('projects', $projects);
		$template->set_data($this->get_data());
		$template->display();
	}


	// 项目详情
	public function guest_detail()
	{
		$project_id = get('project_id', 0, 'int');
		if(!$project_id) exit('变量{project_id}缺失');

		$project = bone::get_table('project');
		$project->load($project_id);

		$model = bone::get_model('project');
		$project->ticket_count = $model->get_ticket_count($project->id);
		$project->completed_ticket_count = $model->get_completed_ticket_count($project->id);
		$project->progress = $model->get_progress($project);
		$project->develop_progress = $model->get_develop_progress($project);
		$project->debug_progress = $model->get_debug_progress($project);

		$model = bone::get_model('ticket');
		$tickets = $model->get_tickets($project_id);

		$template = bone::get_template('project.guest_detail');
		$template->set_title($project->name.' 详情');
		$template->set('project', $project);
		$template->set('tickets', $tickets);
		$template->set_data($this->get_data());
		$template->display();
	}


	// 客户查看项目列表
	public function customer_list()
	{
		$my = bone::get_user();
		$model = bone::get_model('project');
		$projects = $model->get_customer_projects($my->id);

		foreach($projects as $project)
		{
			$project->ticket_count = $model->get_ticket_count($project->id);
			$project->completed_ticket_count = $model->get_completed_ticket_count($project->id);
			$project->progress = $model->get_progress($project);
		}

		$template = bone::get_template('project.customer_list');
		$template->set_title('项目列表');
		$template->set('projects', $projects);
		$template->set_data($this->get_data());
		$template->display();
	}


	// 客户查看项目详情
	public function customer_detail()
	{
		$project_id = get('project_id', 0, 'int');
		if(!$project_id) exit('变量{project_id}缺失');

		$my = bone::get_user();

		$project = bone::get_table('project');
		$project->load($project_id);

		if($project->customer_id == $my->id) exit('你没有权限!');

		$model = bone::get_model('project');
		$project->ticket_count = $model->get_ticket_count($project->id);
		$project->completed_ticket_count = $model->get_completed_ticket_count($project->id);
		$project->progress = $model->get_progress($project);
		$project->develop_progress = $model->get_develop_progress($project);
		$project->debug_progress = $model->get_debug_progress($project);

		$template = bone::get_template('project.customer_detail');
		$template->set_title($project->name.' 详情');
		$template->set('project', $project);
		$template->set_data($this->get_data());
		$template->display();
	}

	// 项目负责人查看项目列表
	public function manager_list()
	{

	}

	// 项目负责人查看项目详情
	public function manager_detail()
	{

	}






	// 开发人员查看项目列表	
	public function developer_list()
	{
	}

	// 开发人员查看项目详情
	public function developer_detail()
	{
	}

	// 管理员查看项目列表	
	public function admin_list()
	{
	}

	// 管理员查看项目详情
	public function admin_detail()
	{
	}
}
?>